package com.itheima.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author tongchen
 * @create 2022-11-29 19:39
 */
public class SessionnFactroyUtils {
    //创建静态代码块，使sql工厂只创建1次
    //创建临时变量（拓宽作用域）
     static SqlSessionFactory factory=null;
    static{
        String resource = "mybatis-config.xml";
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream(resource);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

    }
    public static SqlSessionFactory getFactory(){
        return factory;
    }
}
